package org.dtrd.modules.system.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dtrd.modules.system.entity.bean.BannerBean;
import org.dtrd.modules.system.entity.po.DtrdExtYwDicBanner;
import org.dtrd.modules.system.mapper.DtrdExtYwDicBannerMapper;
import org.dtrd.modules.system.service.IDtrdExtYwDicBannerService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 萧
 * @date 2021-09-13 17:31:25
 **/
@Service
@DS("multi-datasource1")
public class DtrdExtYwDicBannerServiceImpl extends ServiceImpl<DtrdExtYwDicBannerMapper, DtrdExtYwDicBanner> implements IDtrdExtYwDicBannerService {

    @Override
    public List<BannerBean> selectBannerByType(Integer type) {
        List<DtrdExtYwDicBanner> list = baseMapper.selectListByType(type);
        if (list != null) {
            List<BannerBean> dataList = new ArrayList<>();
            list.stream().map(bannerVo -> {
                BannerBean banner = new BannerBean();
                banner.setId(bannerVo.getDataId());
                banner.setName(bannerVo.getBannerName());
                banner.setDescription(bannerVo.getBannerDescription());
                banner.setType(bannerVo.getBannerType());
                banner.setHyperlink(bannerVo.getBannerHyperlink());
                banner.setImgUrl(bannerVo.getBannerImg());
                banner.setHiddenTitleBar(bannerVo.getBannerHiddenTitle());
                banner.setNeedParams(bannerVo.getBannerNeedParams());
                return banner;
            }).forEach(dataList::add);
            return dataList;
        }
        return null;
    }
}
